package com.ffcs.web.controllers;

import java.io.IOException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ffcs.web.model.entity.PicNews;
import com.ffcs.web.model.entity.WxUser;
import com.ffcs.web.services.CommonService;

@Controller
public class CommonController {

private Logger logger = Logger.getLogger(CommonController.class);
	
	@Autowired
	private CommonService commonService;
	
	@RequestMapping("commonRedirectUri")
	public void commonRedirectUri(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
		String code=request.getParameter("code");
		String url=request.getParameter("state");
		WxUser wxUser=commonService.getOpenId(code);
		request.getSession().setAttribute("wxUser",wxUser);
		
		logger.info("授权完成，继续前往:--->"+url);
		url=URLDecoder.decode(url);
		logger.info("授权完成，继续前往:--解密后-->"+url);
		response.sendRedirect(url);
		
	}
}
